#include <59header.h>

/* Usage: ./08_my_ls dirname  */
int main(int argc, char *argv[]){
    ARGS_CHECK(argc, 2);

    DIR *dirp = opendir(argv[1]);
    ERROR_CHECK(dirp, NULL, "opendir");

    struct dirent* direntp;
    // 记录dir2目录项的位置，然后再循环结束后返回该位置
    // 所以要判断等于file1目录项时记录
    //long loc;
    while((direntp = readdir(dirp)) != NULL){
        printf("inode num = %lu, reclen = %hu, "
               "file type = %u, file name = %s\n",
               direntp ->d_ino,
               direntp -> d_reclen,
               direntp -> d_type,
               direntp -> d_name
              );
        //if(strcmp("file1", direntp->d_name) == 0){
        //    loc = telldir(dirp);
        //}
    }
    printf("---------------------------------------\n");
    // 将目录流的指针返回dir2目录项
    //seekdir(dirp, loc);
    rewinddir(dirp);
    direntp = readdir(dirp);
    printf("inode num = %lu, reclen = %hu, "
           "file type = %u, file name = %s\n",
           direntp ->d_ino,
           direntp -> d_reclen,
           direntp -> d_type,
           direntp -> d_name
          );

    closedir(dirp);
    return 0;
}   

